/*!
 * @author : ZhaoYanbo
 * @email  : zyb920@hotmail.com
 * @created: 2020-10-31
 * @version: 1.0.0.0
 *
 */

#ifndef OPENALENGINE_H
#define OPENALENGINE_H

#include "al.h"
#include "alc.h"

class OpenALEngine
{
public:
    OpenALEngine();
    ~OpenALEngine();

    void play();
    void stop();
    void togglePlay();
    void setVolume(float v);
    float getVolume() const;
    int openAudioFromQueue(char* data,int dataSize,int aSampleRate,int aBit ,int aChannel);
    bool updateQueue();

    bool isEnd() const;

private:
    int init();
    void clean();

public:
    int m_numprocessed = 0;             //队列中已经播放过的数量
    int m_numqueued = 0;                //队列中缓冲队列数量
    long long m_IsplayBufferSize = 0;   //已经播放了多少个音频缓存数目
    double m_oneframeduration = 0.0;    //一帧音频数据持续时间(ms)

    float m_volume = 0.0f;              //当前音量volume取值范围(0~1)

    int m_samplerate = 0;               //采样率
    int m_bit = 0;                      //样本值
    int m_channel = 0;                  //声道数
    int m_datasize = 0;                 //一帧音频数据量

private:
    ALCdevice * m_Devicde = nullptr;          //device句柄
    ALCcontext * m_Context = nullptr;         //device context
    ALuint m_outSourceId = 0;                 //source id 负责播放
};

#endif // OPENALENGINE_H
